<?php
namespace App\Api\Repositories\Article;

use App\Models\Article\Article as Model;
use Illuminate\Support\Facades\Cache;

class ArticleRepositories{
    protected $eloquentClass = Model::class;

    public function get_data($id){
        return Cache::remember('article:' . $id, 86400, function() use ($id){
            return $this->eloquentClass::where('id', $id)->first();
        });
    }

    /**
     * 清除缓存
     *
     * @param string $key 缓存键值，也是option表的type字段
     * @return void
     */
    public function delete_cache($id){
        Cache::pull('article:' . $id);
    }
}